
layui.use(['form'], function () {
    var form = layui.form;
    var $ = layui.$;
    var layer = layui.layer;

    // 表单验证
    form.verify({
      required: function (value, item) {
        if (!value) {
          return '该项为必填项';
        }
      }
    });

    form.on('submit(rpwd)', function (data) {
      var oldPwd = data.field.oldpassword; // 原始密码
      var newPwd = data.field.newpassword; // 新密码
      var reNewPwd = data.field.rnewpassword; // 确认新密码

      
      var requestData = {
        id: layui.data('shop').id,
        oldPassword: oldPwd,
        newPassword: newPwd,
        rNewPassword: reNewPwd
      };

      axios.post(`http://localhost:9000/users/rpwd`, requestData, {
        headers: {
          'authorization': layui.data('shop').token
        }
      })
        .then(function (response) {
          if (response.data.code === 1) {
            layer.msg(response.data.message, { icon: 1 });
            layui.data('shop', null)
            location.href = './login.html'
          } else {
            layer.msg(response.data.message, { icon: 0 })
          }
        })

      return false
    });
  });